package liuch.socketdemov1;

import java.io.*;
import java.net.Socket;

public class SocketHander implements Runnable {

    private Socket socket;

    public SocketHander(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        try {
            // 接受客户端信息
            InputStream inputStream = socket.getInputStream();
            InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "UTF-8");
            BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
            while (true) {
                System.out.println("客户端说：" + bufferedReader.readLine());
            }

            // 发送给客户端信息
//            OutputStream outputStream = socket.getOutputStream();
//            OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream, "UTF-8");
//            PrintWriter printWriter = new PrintWriter(outputStreamWriter, true);
//            printWriter.println("你好，客户端！");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
